/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package PCR;

import Enums.ProjectType;
import javax.swing.JOptionPane;

/**
 *
 * @author marwa
 */
public class NewPro extends javax.swing.JInternalFrame {

    /**
     * Creates new form NewPro
     */
    String ImageTitleS;
    String sampleNumber;
    String markerType;
    String markers;
    WorkArea obj;
    Toolbox toolbox;
    int hight;
    int width;
    int newpos;

    public NewPro() {
        initComponents();
        MainFrame frm = (MainFrame) java.awt.Window.getWindows()[0];
        hight = (frm.getHeight() / 2) - (this.getHeight());
        width = frm.getWidth() / 2 - (this.getWidth() / 2);

        this.setLocation(width, hight);
        this.getRootPane().setDefaultButton(createButton);
        obj = new WorkArea(ImageTitleS, true, "PRO");

        newpos = 20;

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        ImageTitle = new javax.swing.JTextField();
        MarkerCompobox = new javax.swing.JComboBox();
        createButton = new javax.swing.JButton();
        cancelbutton = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        SamplesCompobox = new javax.swing.JComboBox();

        setClosable(true);
        setTitle("New Protein Image");

        jLabel1.setText("Title:");

        jLabel2.setText("Marker:");

        ImageTitle.setText("Untitled");

        MarkerCompobox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Type 1", "Type 2", "Type 3" }));

        createButton.setText("Create");
        createButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                createButtonActionPerformed(evt);
            }
        });

        cancelbutton.setText("Cancel");
        cancelbutton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelbuttonActionPerformed(evt);
            }
        });

        jLabel3.setText("Samples:");

        SamplesCompobox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "4 Samples", "8 Samples" }));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(59, 59, 59)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(SamplesCompobox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addGap(18, 18, 18)
                                .addComponent(MarkerCompobox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addGap(38, 38, 38)
                                .addComponent(ImageTitle, javax.swing.GroupLayout.PREFERRED_SIZE, 187, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(57, 57, 57)
                        .addComponent(createButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 92, Short.MAX_VALUE)
                        .addComponent(cancelbutton)
                        .addGap(78, 78, 78))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(45, 45, 45)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(ImageTitle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(SamplesCompobox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(MarkerCompobox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 82, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cancelbutton)
                    .addComponent(createButton))
                .addGap(41, 41, 41))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cancelbuttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelbuttonActionPerformed

        this.setVisible(false);
    }//GEN-LAST:event_cancelbuttonActionPerformed

    private void createButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createButtonActionPerformed

        ImageTitleS = CheckTitle(ImageTitle.getText());
        sampleNumber = (String) SamplesCompobox.getSelectedItem();
        markerType = (String) MarkerCompobox.getSelectedItem();
//        markers = nOmarkers.getText();
        //validate max number for markers
        try {
            //if (validateMarkersNumber(Integer.parseInt(markers))) {
                MainFrame test = (MainFrame) this.getParent().getParent().getParent().getParent().getParent();

                obj.setTitle(ImageTitleS);
                obj.wheelBandsDrawer(Integer.parseInt(sampleNumber.split(" ")[0]));
                obj.setVisible(true);
                obj.setSize(800, 600);
                obj.setLocation(220, 10);
                obj.setProjectType(ProjectType.PRO);
                obj.setSampleSize(Integer.parseInt(sampleNumber.split(" ")[0]));
                //for (int count = 1; count <= Integer.parseInt(markers); count++) {
                    obj.drawProteinMarker(markerType, Integer.parseInt(sampleNumber.split(" ")[0]), newpos);
                  //  newpos += 140;
               // }
  /*              int markerCount = Integer.parseInt(markers);
                switch (markerCount) {
                    case 2:
                        Integer[] sample16Position_2 = {5, 75, 145, 215, 285, 355, 425, 495, 565, 635, 705, 775, 845, 915, 985, 1055, 1125};
                        Integer[] sample8Position_2 = {3, 136, 269, 402, 535, 668, 801, 934, 1067};
                        Integer[] sample4Position_2 = {3, 350, 544, 833, 1122};
                        obj.set16Position(sample16Position_2);
                        obj.set8Position(sample8Position_2);
                        obj.set4Position(sample4Position_2);
                        break;
                    case 3:
                        Integer[] sample16Position_3 = {5, 75, 145, 215, 285, 355, 425, 495, 565, 635, 705, 775, 845, 915, 985, 1055, 1125};
                        Integer[] sample8Position_3 = {3, 136, 269, 402, 535, 668, 801, 934, 1067};
                        Integer[] sample4Position_3 = {3, 255, 544, 833, 1122};
                        obj.set16Position(sample16Position_3);
                        obj.set8Position(sample8Position_3);
                        obj.set4Position(sample4Position_3);
                        break;
                }*/
                obj.toFront();
                obj.getBandsPanel().setSampleType(sampleNumber);
                obj.grabFocus();
                test.setSelectedWorkArea(obj);
                super.getDesktopPane().add(obj);
                
                this.setVisible(false);

                toolbox = test.getToolbox();
                toolbox.initializeTools(ProjectType.PRO);

                test.getPositioningToolbar().setVisible(true);


            //} else {
              //  JOptionPane.showMessageDialog(null, "There should be at least  \"1\" marker to draw !", "Alert", JOptionPane.ERROR_MESSAGE);
            //}
        } catch (java.lang.NumberFormatException e) {
            JOptionPane.showMessageDialog(null, "Please Insert the number of markers that will be used,\n Or leave it with default \"1\"", "Alert", JOptionPane.ERROR_MESSAGE);
        }

    }//GEN-LAST:event_createButtonActionPerformed

    private String CheckTitle(String text) {
        if (text.equals("Untitled") || text.equals("")) {
            return "Untitled";
        } else {
            return text;
        }

    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField ImageTitle;
    private javax.swing.JComboBox MarkerCompobox;
    private javax.swing.JComboBox SamplesCompobox;
    private javax.swing.JButton cancelbutton;
    private javax.swing.JButton createButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    // End of variables declaration//GEN-END:variables

    private boolean validateMarkersNumber(Integer markers) {
        if (markers == 0) {
            return false;
        }
        return true;
    }
}
